package main
import (
	"fmt"
	"math/rand"
	"strconv"
	"time"
)
//channel 是引用类型，必须在make之后才能使用
func main(){
	personchan := make(chan Person,10)
	rand.Seed(time.Now().UnixNano())
	for i:=0;i<10;i++{
		var person Person = Person{
			Name : "person"+strconv.Itoa(rand.Intn(100)+1),
			Age : rand.Intn(100)+1,
			Address : "address"+strconv.Itoa(rand.Intn(100)+1),
		}
		personchan <- person
	}
	close(personchan)  //先关闭管道，再用for-range遍历,否则会死锁
	for v:= range personchan{
		fmt.Println("Person~ : ",v)
	}
	//<- personchan  再取会报错
}


type Person struct{
	Name string
	Age int
	Address string
}